package com.iman.fetion.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginServlet extends HttpServlet {

	/**
	 * The doGet method of the servlet. <br>
	 * 
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request
	 *            the request send by the client to the server
	 * @param response
	 *            the response send by the server to the client
	 * @throws ServletException
	 *             if an error occurred
	 * @throws IOException
	 *             if an error occurred
	 */
	// http://localhost:8080/fetion/servlet/LoginServlet?idnum=123&mb=15900600380&fid=88888888&pwd=111111a
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		FetionConnector fc = new FetionConnector();

		String idnum = request.getParameter("idnum");
		String mobile = request.getParameter("mb");
		String fetionId = request.getParameter("fid");
		String password = request.getParameter("pwd");

		int status=fc.login(mobile, fetionId, password, idnum);
		
		if(status==400){
			response.setContentType("text/html");
			PrintWriter out = response.getWriter();
			out.write("400");
			out.flush();
			out.close();
		}else{
			response.setContentType("text/html");
			PrintWriter out = response.getWriter();
			out.write("200");
			out.flush();
			out.close();
		}
	

	}

}
